



#ifndef _BMS_CAN_MSG_H_
#define _BMS_CAN_MSG_H_

#include "stdint.h"
#include "arm_math.h"


// ------------------------ clean robot battery BMS ---------------------------

#define ID_CAN_BMS_STATUS  0x18FF28F4

typedef struct
{
	
	union
	{
		struct
		{
			uint8_t line_connect    :1;
			uint8_t charge_FSM      :1;
			uint8_t over_discharge  :1;
			uint8_t battery_ready   :1;
			uint8_t sw_discharge    :1;
			uint8_t sw_charge       :1;
			uint8_t                 :2;
			
			uint8_t  soc;
			
			uint16_t current;
			uint16_t voltage;
			
			uint8_t  fault_level;
			uint8_t  fault_code;
			
		}bit;

		uint8_t data[8];
		
	}raw;
	
	uint8_t rece_flg;
	uint8_t rece_cnt;
	
	float32_t current_A;
	float32_t voltage_V;
	
	void(*fun_data_analyse)(void);

}STR_BMS_STATUS;


extern void BMS_rece_canmailbox_set(uint8_t fifo_num);
extern void BMS_data_analyse(void);

extern STR_BMS_STATUS bmsStatus;







// ------------------------ service robot battery BMS ---------------------------

#define ID_CAN_SER_BMS_STATUS_X1   0x0050
#define ID_CAN_SER_BMS_STATUS_X2   0x0051

typedef struct
{
	union
	{
		struct
		{
			uint8_t lifecnt;
			
			uint8_t charge_FSM  :1;
			uint8_t alarm_FSM   :1;
			uint8_t propect_FSM :1;
			uint8_t fault_FSM   :1;
			uint8_t             :4;
			
			uint16_t volatage;
			uint16_t current;
			uint16_t soc;
		
		}bit;
		
		uint8_t data[8];
	
	}FSM1;
	
	union
	{
		struct
		{
			uint16_t health_rate;
			uint16_t charge_cnt;
			
			uint8_t  bat_temp;
			uint8_t  fault_codeX1;
			uint8_t  fault_codeX2;
			uint8_t  fault_codeX3;
		
		}bit;
		
		uint8_t data[8];
	
	}FSM2;
	
	uint8_t rece_flg;
	uint8_t rece_cnt;
	
	float32_t current_A;
	float32_t voltage_V;
	float32_t soc;
	float32_t health_rate;
	
	uint8_t   bat_temp;
	
	void(*fsm1_data_analyse)(void);
	void(*fsm2_data_analyse)(void);

}STR_SER_BMS_STATUS;



#define ID_CAN_TAR_BMS_REQ   0x0060

#define COMM_PERIOD_BMS_REQ     1000
#define COMM_PERIOD_CLEAN_CTRL  300


typedef union
{
	struct
	{
		uint8_t  re_capacity;
		uint8_t  num_version;
		uint8_t  cell_vot_x1;
		uint8_t  cell_vot_x2;
	};
	
	uint8_t data[8];
	
}STR_TAR_BMS_REQUST;
















extern void ser_BMS_fsm1_analyse(void);
extern void ser_BMS_fsm2_analyse(void);


extern STR_SER_BMS_STATUS serBmsStatus;


#endif




